home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1992 June: ROMin Holiday / ADC Developer CD (1992-06) (''ROMin Holiday'')_iso / Developer Connection - 06-1992.iso / Periodicals / develop / develop 10 code / GWorld Drawing / GWorld Routines / CalcDeltasFast.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-04-08  |  2.7 KB  |  77 lines  |  [TEXT/KAHL]

  1. /* Faster version of calculate deltas which precomputes the luminance for the image
  2. ** before calculating deltas.
  3. ** Note: Both GWorlds (src any depth, dst 8-bit grayscale)
  4. ** must be allocated when this routine is called.
  5. */
  6.  
  7. #include "DemoRoutines.h"
  8.  
  9. void FastCalculateDeltas( GWorldPtr src, GWorldPtr dst )
  10. {
  11. PixMapHandle    srcPixMap, dstPixMap;
  12. short        srcRowBytes, dstRowBytes;
  13. long            *srcBaseAddr, *dstBaseAddr, *dstAddr;
  14. unsigned char    *srcAddr1;
  15. char            mmuMode;
  16. short        row, column;
  17. unsigned char    lum1,lum2;
  18. unsigned long    dstLong;
  19. short        width, height;
  20. GDHandle        oldGD;
  21. GWorldPtr        oldGW;
  22.  
  23.     srcPixMap = GetGWorldPixMap ( src );
  24.     dstPixMap = GetGWorldPixMap ( dst );
  25.  
  26.     if ( LockPixels ( srcPixMap ) && LockPixels( dstPixMap) ) 
  27.     {    /* lock the pixmaps */
  28.         GetGWorld(&oldGW,&oldGD);
  29.         SetGWorld(dst,nil);
  30.         CopyBits( (BitMap*)*srcPixMap, (BitMap*)*dstPixMap, &(**srcPixMap).bounds, &(**dstPixMap).bounds, srcCopy, 0L );
  31.         SetGWorld( oldGW, oldGD );
  32.  
  33.         srcBaseAddr = (long *) GetPixBaseAddr ( srcPixMap );    /* get the address of the pixmap */
  34.         srcRowBytes = (**srcPixMap).rowBytes & 0x7fff;            /* get the row increment */
  35.         dstBaseAddr = (long *) GetPixBaseAddr ( dstPixMap );    /* get the address of the pixmap */
  36.         dstRowBytes = (**dstPixMap).rowBytes & 0x7fff;            /* get the row increment */
  37.         width = (**srcPixMap).bounds.right-(**srcPixMap).bounds.left;
  38.         height = (**srcPixMap).bounds.bottom-(**srcPixMap).bounds.top;
  39.     
  40.         mmuMode = true32b;
  41.         SwapMMUMode ( &mmuMode );                        /* set the MMU to 32-bit mode */
  42.         for ( row = 0; row < height; row++ ) 
  43.         {
  44.             srcAddr1 = (unsigned char *)dstBaseAddr;
  45.             dstAddr = dstBaseAddr;
  46.             lum1 = *srcAddr1++;        /* get luminance of src pixel */
  47.             for ( column = 0; column < ((width-1)/4); column++ ) 
  48.             {
  49.                 /* 
  50.                 ** Do a long in the destination (4 pixels)
  51.                 ** This is o.k. since memory blocks are always long word aligned. 
  52.                 ** Thus, we will never write over the right hand edge.
  53.                 */
  54.                 dstLong = 0;
  55.                 lum2 = *srcAddr1++;
  56.                 dstLong = (unsigned char)((0x100 + lum1 - lum2)>>1);
  57.                 dstLong = dstLong << 8;
  58.                 lum1 = *srcAddr1++;
  59.                 dstLong |= (unsigned char)((0x100 + lum2 - lum1)>>1);
  60.                 dstLong = dstLong<<8;
  61.                 lum2 = *srcAddr1++;
  62.                 dstLong |= (unsigned char)((0x100 + lum1 - lum2)>>1);
  63.                 dstLong = dstLong << 8;
  64.                 lum1 = *srcAddr1++;
  65.                 dstLong |= (unsigned char)((0x100 + lum2 - lum1)>>1);
  66.                 *dstAddr++ = dstLong;
  67.             }
  68.     
  69.             srcBaseAddr = (long *) ( (char *) srcBaseAddr + srcRowBytes );    /* go to the next row */
  70.             dstBaseAddr = (long *) ( (char *) dstBaseAddr + dstRowBytes );    /* go to the next row */
  71.         }
  72.         SwapMMUMode ( &mmuMode );                        /* restore the previous MMU mode */
  73.         UnlockPixels ( srcPixMap );                        /* unlock the pixmap */
  74.         UnlockPixels ( dstPixMap );                        /* unlock the pixmap */
  75.     }
  76. }
  77.